package com.ruoyi.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CorpInfo;
import com.ruoyi.system.service.ICorpInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 管理授权企业Controller
 * 
 * @author 刘治军
 * @date 2023-06-19
 */
@Controller
@RequestMapping("/system/info")
public class CorpInfoController extends BaseController
{
    private String prefix = "system/info";

    @Autowired
    private ICorpInfoService corpInfoService;

    @RequiresPermissions("system:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询管理授权企业列表
     */
    @RequiresPermissions("system:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CorpInfo corpInfo)
    {
        startPage();
        List<CorpInfo> list = corpInfoService.selectCorpInfoList(corpInfo);
        return getDataTable(list);
    }

    /**
     * 导出管理授权企业列表
     */
    @RequiresPermissions("system:info:export")
    @Log(title = "管理授权企业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CorpInfo corpInfo)
    {
        List<CorpInfo> list = corpInfoService.selectCorpInfoList(corpInfo);
        ExcelUtil<CorpInfo> util = new ExcelUtil<CorpInfo>(CorpInfo.class);
        return util.exportExcel(list, "管理授权企业数据");
    }

    /**
     * 新增管理授权企业
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存管理授权企业
     */
    @RequiresPermissions("system:info:add")
    @Log(title = "管理授权企业", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CorpInfo corpInfo)
    {
        return toAjax(corpInfoService.insertCorpInfo(corpInfo));
    }

    /**
     * 修改管理授权企业
     */
    @RequiresPermissions("system:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CorpInfo corpInfo = corpInfoService.selectCorpInfoById(id);
        mmap.put("corpInfo", corpInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存管理授权企业
     */
    @RequiresPermissions("system:info:edit")
    @Log(title = "管理授权企业", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CorpInfo corpInfo)
    {
        return toAjax(corpInfoService.updateCorpInfo(corpInfo));
    }

    /**
     * 删除管理授权企业
     */
    @RequiresPermissions("system:info:remove")
    @Log(title = "管理授权企业", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(corpInfoService.deleteCorpInfoByIds(ids));
    }
}
